<!--#begin grp_maintree -->
<script type="text/javascript" src="{ babInstallPath }scripts/ul_tree.js"></script>

<script type="text/javascript">

function table_name(obj)
{
	if (obj.name.match(/\[(.*?)\]\[/))
		return RegExp.$1;
}

function checkbox_onClick()
{
	checkChildren(this);
}

function checkChildren(checkbox)
{
	var obj = checkbox.parentNode;
	while ('' == obj.id) {
		obj = obj.parentNode;
	}

	var inputs = obj.getElementsByTagName('INPUT');
	window.console && window.console.debug(checkbox.name + ' ' + inputs.length);
	var nbInputs = inputs.length
	for (var i = 0; i < nbInputs; i++) {
//	for (var i = 0; i < inputs.length; i++) {
		var input = inputs[i];
		if (checkbox.bab_tableName == input.bab_tableName && checkbox != input) {
			input.disabled = input.checked = checkbox.checked;
		}
	}

}

function macl_set_checkbox_events()
{
	var nbChecked = 0;
	var checkboxes = document.getElementById('bab_groups_tree').getElementsByTagName('INPUT');
	var nbCheckboxes = checkboxes.length;
	for (var i = 0; i < nbCheckboxes; i++) {
		var checkbox = checkboxes[i];
		checkbox.bab_tableName = table_name(checkbox);
	}
	for (var i = 0; i < nbCheckboxes; i++) {
		var checkbox = checkboxes[i];
		var nameStart = checkbox.name.charAt(0);
		if ((checkbox.value < 3 && 'g' == nameStart) || 't' == nameStart) {
			checkbox.onclick = checkbox_onClick;
			if (checkbox.checked && !checkbox.disabled) {
				nbChecked++;
				checkChildren(checkbox);
			}
		}
	}
}

function macl_switch_view_on(table, tablenum)
{

	var menu = document.getElementById('bab_groups_acl').getElementsByTagName('li');
	for(var i = 0; i < menu.length; i++ )
		{
		menu[i].className = '';
		}
	
	if (null == table) {
		table = menu[0].id.substr(16);
		tablenum = 1;
		}

	document.getElementById('macl_link_table_'+table).className = 'bab_tree BabMenuActiveBackground';
	
	document.getElementById('bab_groups_tree').className = 'bab_tree BabLoginCadreBackground displaytable'+tablenum;
}


function hideNonMultipleTable()
{
 if (document.getElementById('bab_groups_acl').getElementsByTagName('li').length <= 1)
	{
	document.getElementById('bab_groups_acl').style.display = 'none';
	}
}
</script>

<form method="post" action="{ babPhpSelf }">
<input type="hidden" name="tg" value="{ target }" />
<input type="hidden" name="idx" value="{ index }" />
<input type="hidden" name="item" value="{ id_object }" />
<input type="hidden" name="table" value="" />
<input type="hidden" name="what" value="" />
<input type="hidden" name="{ return }" value="update" />
<!--#in get_next_hidden_field -->
<input type="hidden" name="{ sHiddenFieldName }" value="{ sHiddenFieldValue }" />
<!--#endin get_next_hidden_field -->

<div id="bab_groups_acl" class="BabLoginCadreBackground">
	<ul class="BabLoginMenuBackground">
		<!--#in getnexttable -->
		<li id="macl_link_table_{ table }" onclick="macl_switch_view_on('{ table }',{ tablenum })">{ title }
		<!--#if msgerror -->
		&nbsp;<img src="{ babSkinPath }images/Puces/broken.png" alt="{ t_broken }" title="{ t_broken }" />
		<!--#endif msgerror -->
		</li>
		<!--#endin getnexttable -->
	</ul>
</div>

<br />




<div id="bab_groups_tree" class="bab_tree BabLoginCadreBackground" style="padding: 1px">

<p class="BabSiteAdminTitleFontBackground">
	<a href="javascript:tree.expand();" class="expand">{ t_expand_all }</a> 
	<a href="javascript:tree.collapse();" class="collapse">{ t_collapse_all }</a>
	<a href="#" onclick="tree.expandChecked(); return false;" class="expandchecked">{ t_expand_checked }</a>
</p>


	<div  class="tree"  style="position: relative">
	
		<ul>
		<!--#in firstnode -->
			<li id="bab_ovgroup_{ arr[id] }">
				<div class="line">
				
				<img src="{ babSkinPath }images/Puces/folder_group.gif" alt="{ t_group }" />
				{ arr[name] }
	
					<span class="right_elements">
						<!--#in getnexttable -->
						<input type="checkbox" class="tablecol{ tablenum }" name="group[{ table }][]" value="{ id_group }" <!--#if checked --> checked="checked" <!--#endif checked --> <!--#if disabled --> disabled="disabled" <!--#endif disabled --> />
						<!--#endin getnexttable -->
					</span>
				</div>
				{ tpl_tree }
			</li>
		<!--#endin firstnode -->
		</ul>
	</div>


	<!--#if countsets -->
	<p class="BabSiteAdminTitleFontBackground">{ t_sets_of_groups }</p>
	<div class="tree sets">
	<ul>
	<!--#in getnextset -->
		<!--#if altbg --><li class="BabSiteAdminFontBackground"><!--#else altbg --><li class="BabForumBackground1"><!--#endif altbg -->
			<div class="line">
			{ arr[name] }
				<span class="right_elements">
				<!--#in getnexttable -->
				<input type="checkbox" class="tablecol{ tablenum }" name="group[{ table }][]" value="{ id_group }" <!--#if checked --> checked="checked" <!--#endif checked --> <!--#if disabled --> disabled="disabled" <!--#endif disabled --> />
				<!--#endin getnexttable -->
				</span>
			</div>
		</li>
	<!--#endin getnextset -->
	</ul><br />
	</div>
	<!--#endif countsets -->
</div>

<br />

<div align="center">
	<input type="submit" value="{ t_record }" />
</div>

</form>

<script type="text/javascript">
var tree = new bab_ul_tree('bab_groups_tree');

window.console && window.console.time('full init');

window.console && console.time('processList');
tree.processList();
window.console && console.timeEnd('processList');

tree.collapse();

document.getElementById('bab_groups_tree').display = 'none';

window.console && console.time('setCheckBoxEvents');
macl_set_checkbox_events();
window.console && console.timeEnd('setCheckBoxEvents');

window.console && console.time('switchViewOn');
macl_switch_view_on();
window.console && console.timeEnd('switchViewOn');

window.console && console.time('expandChecked');
if (!tree.expandChecked()) {
	tree.expandToItem('bab_ovgroup_1');
}
window.console && console.timeEnd('expandChecked');

document.getElementById('bab_groups_tree').display = '';

window.console && window.console.timeEnd('full init');

// hideNonMultipleTable();
</script>
<!--#end grp_maintree -->

<!--#begin grp_childs -->
	<ul>
		<!--#in getnextgroup -->
		<li id="bab_ovgroup_{ arr[id] }">
			<div class="line">
			<img src="{ babSkinPath }images/Puces/folder_group.gif" alt="{ t_group }" />
			<!--#in getnexttable --><!--#if id_group "> 2" --><input type="checkbox" class="tablecol{ tablenum }" name="tree[{ table }][]" value="{ arr[id] }" <!--#if treechecked --> checked="checked" <!--#endif treechecked --> /><!--#endif id_group --><!--#endin getnexttable -->
			
			<span class="bab-node-title">{ arr[name] }</span>

			<span class="right_elements"><!--#in getnexttable --><input type="checkbox" class="tablecol{ tablenum }" name="group[{ table }][]" value="{ id_group }" <!--#if checked --> checked="checked" <!--#endif checked --> <!--#if disabled --> disabled="disabled" <!--#endif disabled --> /><!--#endin getnexttable --></span>

			</div>
			{ subtree }
		</li>
		<!--#endin getnextgroup -->
	</ul>
<!--#end grp_childs -->